<?php

namespace app\common\validate;

class ReceiverValidate extends BaseValidate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        're_id'=>'require|integer|>:0|isReceiverExist'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [];

    // 验证场景
    protected $scene = [
        'complete'=>'sceneComplete',
        'isCurrentUser'=>['re_id'],
    ];

    // 订单是否可以完成
    public function sceneComplete()
    {
        return $this->only(['re_id'])->append('re_id','isReceiverComplete');
    }

    // 接取订单是否存在
    protected function isReceiverExist($value, $rule='', $data='', $field='')
    {
        if (\app\common\model\Receiver::field('id')->find($value)) return true;
        return "该订单已不存在";
    }

    // 订单是否可以进行完成操作
    protected function isReceiverComplete($value, $rule='', $data='', $field='')
    {
        $status = \app\common\model\Receiver::field('status')->find($value)['status'];
        if ($status == 2) {
            return true;
        }
        return "该任务不可进行完成操作";
    }
}
